using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Graphs
{
	class GraphDraw
	{

		public static void DrawGraph(CGraph graph, Graphics g, float scale)
		{
			Pen edgePen = new Pen(Color.Gray);
			edgePen.Width = 2;
			Pen edgePen2 = new Pen(Color.Red);
			edgePen2.Width = 6;

			

			Brush nodeBrush = Brushes.Black;
			Brush nodeBrush2 = Brushes.Red;


			g.Clear(Color.White);
			Random r = new Random();
			CEdge e1 = graph.Edges [0];
			PointF delta = graph.Bounds.Location;
			Console.WriteLine(delta);
			Console.WriteLine(graph.Bounds.Size);
			delta.X *= scale;
			delta.Y *= scale;


			foreach (CEdge e in graph.Edges)
			{
				PointF sLoc = e.StartNode.Location;
				PointF eLoc = e.EndNode.Location;
				sLoc.X *= scale;
				sLoc.Y *= scale;
				sLoc.X -= delta.X;
				sLoc.Y -= delta.Y;

				eLoc.X *= scale;
				eLoc.Y *= scale;
				eLoc.X -= delta.X;
				eLoc.Y -= delta.Y;


				//Console.WriteLine(eLoc);

				edgePen.Color = Color.FromArgb(r.Next(255), r.Next(255), r.Next(255));
				if (e.HiLite)
				{
					//g.DrawLine(edgePen2, e.StartNode.Location, e.EndNode.Location);
					g.DrawLine(edgePen2, sLoc, eLoc);
				}
				else
				{
					//g.DrawLine(edgePen, e.StartNode.Location, e.EndNode.Location);
					g.DrawLine(edgePen, sLoc, eLoc);
				}
			}

			
			foreach (CNode n in graph.Nodes)
			{

				PointF loc = n.Location;
				loc.X *= scale;
				loc.Y *= scale;
				loc.X -= delta.X;
				loc.Y -= delta.Y;

				if (n.HiLite)
				{
					g.FillEllipse(nodeBrush2, new RectangleF(loc.X - 10, loc.Y - 10, 20, 20));
				}
				else
				{
					g.FillEllipse(nodeBrush, new RectangleF(loc.X - 3, loc.Y - 3, 6, 6));
				}
				//g.DrawString(nNode.Name, new Font("Arial", 8), Brushes.Black, loc);

			}



		}


	}
}
